package pos.datos;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;



import pos.dominio.Planeta;

public class JDBCPlanetaDAO implements IPlanetaDAO{

	public List<Planeta> ObtenerPlanetas() {
		
		Connection conn = ConnectionManager.getInstance().checkOut();
        PreparedStatement stmt = null;
        List<Planeta> searchResults = new LinkedList<Planeta>();
        ResultSet result = null;
        
        try {

            String sql = "SELECT * FROM planetas";
            stmt = conn.prepareStatement(sql); 
            stmt.executeQuery();
            result = stmt.executeQuery();

            while (result.next()) {
            
                    Planeta temp=new Planeta();
                    
                    temp.setNombrePlaneta(result.getString("nombrePlaneta"));
                    temp.setDistancia(result.getInt("Distancia"));
                    temp.setMulta(result.getInt("Multa"));
                    temp.setModAgricultura(result.getInt("mod_Agricultura"));
                    temp.setModArmas(result.getInt("mod_Armas"));
                    temp.setModIndustria(result.getInt("mod_Industria"));
                    temp.setModContrabando(result.getInt("mod_Contrabando"));
                    
                    
                    searchResults.add(temp);
            }
        } catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            ConnectionManager.getInstance().checkIn(conn);
            try {
                if (result != null)
                    result.close();
                if (stmt != null)
                    stmt.close();
            } catch (SQLException e) {
            }

        }
            return searchResults;
       
	
}

	
	
	

	
}
	
	

	

